<?php
require_once './config.php';

$username = $_REQUEST['username'];
$password = $_REQUEST['password'];

$sql = "SELECT * from myinfo WHERE username = '$username'";
$result = mysqli_query($conn, $sql);
$data = mysqli_fetch_assoc($result);

if ($data) {
    echo json_encode(array(
        'code' => 0,
        'msg' => '用户名已存在',
    ));
} else {
    $sql = "INSERT INTO userinfo (username, password) VALUES ('$username', '$password')";
    mysqli_query($conn, $sql);

    $rows = mysqli_affected_rows($conn);
    if ($rows > 0) {
        echo json_encode(array(
            'code' => 1,
            'msg' => '注册成功',
        ));
    }
}
